home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 226_01.zip / WORKUP2.C < prev    next >
Text File  |  1993-04-21  |  8KB  |  223 lines

  1.    /*  HEADER:CUG 226;
  2.        TITLE:"ART-CEE";
  3.        VERSION:1.4;
  4.        DESCRIPTION:"Small artificial intelligence inference engine.
  5.  
  6.             ART-CEE is a rule-based general purpose driver capable of working
  7.             with heirarchical and/or propositional information.";
  8.        KEYWORDS:artificial intelligence, inference engines, database;
  9.        SYSTEM:MS-DOS;
  10.        FILENAME:WORKUP2.C;
  11.        SEE-ALSO:WORKUP0.C, WORKUP3.C, WORKUP4.C, MANUAL.TXT, WORKUP0.H,
  12.             WORKUP1.H, HELP1.AIH, HELP2.AIH, HELP3.AIH, HELP4.AIH, ART-CEE.COM;
  13.        AUTHOR:Dan Cheatham;
  14.        COMPILER:MIX-C;
  15.    */
  16.  
  17.  
  18.          /*  art-cee  artificial intelligence inference engine    */
  19.          /*                                                       */
  20.          /*  file:  workup2.c    --  data file i-o                */
  21.          /*                          exclusive groupings routines */
  22.          /*                                                       */
  23.  
  24. #include "workup0.h"
  25. #include "workup1.h"
  26.  
  27. loaddata()
  28.    { FILE *infile;
  29.      int wk1, wk2, wk3, wk5, wk6, wk7;
  30.      printf("\nEnter the name of the file to be read: ");
  31.      gets(currfile);
  32.      infile  = fopen(currfile,"r");
  33.      if (infile  == NULL)
  34.          failfile();
  35.      else
  36.        { fscanf(infile,"%d%d",&wk5,&wk6);
  37.          if (wk5 < wk6 && wk6 < MAX)
  38.           { wk6++; for (wk1 = wk5; wk1 < wk6; wk1++)
  39.             { fscanf(infile,"%d",&wk7);
  40.               wk7++;
  41.               wk3 = fgets(subjs[wk1],wk7,infile);
  42.               wk2 = 0;
  43.               while (wk2 < wk6)
  44.                  {  wk3 = fscanf(infile,"%f",&ft[wk1][wk2]);
  45.                     wk2++;} }
  46.              wk3 = fclose(infile); }
  47.           else
  48.             { printf("\nStart and/or stop positions invalid in file.");
  49.               wk3 = fclose(infile);
  50.               marktime();}}
  51. }
  52.  
  53. presave()
  54.    { int wk5, wk6, wk7; char prompt[2];
  55.      printf("\n\nSave entire database (Y/N)? ");
  56.      gets(prompt);
  57.      if (prompt[0] == 'Y')
  58.          savedata(0,MAX);
  59.      else
  60.       { printf("\nEnter the following:");
  61.         printf("\nPosition of first subject to be saved (0 = start of data),");
  62.         printf("\n the position: ");
  63.         scanf("%d",wk5);
  64.         if (wk5 < MAX)
  65.           {}
  66.         else
  67.           { printf("\nInput is greater than maximum position in data.");
  68.             printf("\nMaximum position used.");
  69.             wk5 = MAX; }
  70.        wk7 = MAX - 1;
  71.        printf("\nPosition of last subject to be saved (%d = end of data)",wk7);
  72.        printf("\n the position: ");
  73.        scanf("%d",wk6);
  74.        if (wk6 < MAX && wk5 < wk6)
  75.             { wk6++; savedata(wk5,wk6); }
  76.        else
  77.          {  printf("\nInvalid limits entered.  Cannot proceed.");
  78.             marktime(); }}
  79. }
  80.  
  81. savedata(wk5,wk6)
  82.    int wk5, wk6;
  83.    { FILE *outfile;  char fname[32];          int wk7, wk8;
  84.      int wk1, wk2, wk3;           char tempfile[32];  float fn1, fn2, fn3, fn4;
  85.      printf("\n%s will be overwritten if you just press",currfile);
  86.      printf("\nenter.  Enter a new file name to avoid this.");
  87.      printf("\nThe name:  ");
  88.      gets(tempfile);
  89.      if (tempfile[0] != '\0' && tempfile[0] != '\n')
  90.             strcpy(fname,tempfile);
  91.      else
  92.             strcpy(fname,currfile);
  93.      outfile = fopen(fname,"w");
  94.      if (outfile == NULL)
  95.          failfile();
  96.      else
  97.        { filestat = 0; wk7 = wk6 - 1;
  98.          printf("\n\nSaving database from positon %d to position %d.",wk5,wk7);
  99.             filestat = fprintf(outfile,"%d %d ",wk5,wk7);
  100.          for (wk1 = wk5; wk1 < wk6; wk1++)
  101.            { wk8 = strlen(subjs[wk1]);
  102.              wk3 =  fprintf(outfile,"%d", wk8);
  103.              if  (wk3 == -1)
  104.                 filestat = 1;
  105.              wk3 = fputs(subjs[wk1],outfile);
  106.              if (wk3 == -1)
  107.                 filestat = 1;
  108.              wk2 = wk5;
  109.              while (wk2 < wk6)
  110.                { wk3   = fprintf(outfile,"%f ",ft[wk1][wk2]);
  111.                  wk2++;
  112.                  if (wk3 != 0)
  113.                    filestat = wk3;}}
  114.           wk3 = fflush(outfile);
  115.           if (wk3 != 0)
  116.              filestat = wk3;
  117.           wk3 = fclose(outfile);
  118.           if (filestat != 0 || wk3 != 0)
  119.               failfile(); }
  120. }
  121.  
  122. filegroup()
  123.    { FILE *infile;  char grpname[32], grpitem[77];
  124.      int wk1, wk2, wk3, wk5, wk6, wk8, wk9, grpmems[MAX];
  125.  
  126.      printf("\nEnter the name of the groups file to be read: ");
  127.      gets(grpname);
  128.      infile  = fopen(grpname,"r");
  129.      if (infile  == NULL)
  130.          wk6 = 1;
  131.      else
  132.        { wk6 = 0; wk9 = 0;
  133.          wk5 = fscanf(infile,"%d",&wk1);
  134.          for (wk2 = 0; wk2 < wk1; wk2++)
  135.             { wk5 = fscanf(infile,"%d",&wk3);
  136.               wk3++;
  137.               wk5 = fgets(grpitem,wk3,infile);
  138.               if (wk5 == NULL)
  139.                    wk6 = 1;
  140.               else
  141.                 { wk8 = findmem(grpitem);
  142.                   if (wk8 < MAX)
  143.                    { grpmems[wk9] = wk8; wk9++; }}}
  144.           wk5 = fclose(infile); }
  145.  
  146.      if (wk6 != 0)
  147.         printf("\nProcedure failed.");
  148.      else
  149.         markgrup(grpmems,wk9);
  150. }
  151.  
  152. findmem(dd1)
  153.    char *dd1;
  154.    { int kw1, kw2, kw3;
  155.      kw3 = MAX + 1; kw1 = 0;
  156.      while (kw1 < MAX && kw3 > MAX)
  157.       { kw2 = strcmp(dd1,subjs[kw1]);
  158.         if (kw2 == 0)
  159.           kw3 = kw1;
  160.         kw1++; }
  161.      return(kw3);
  162. }
  163.  
  164. markgrup(dd1,dd2)
  165.    int *dd1[], dd2;
  166.    { int wd1, wd2, wd3, wd4;
  167.      for (wd1 = 0; wd1 < dd2; wd1++)
  168.        { wd2 = dd1[wd1];
  169.          for (wd3 = 0; wd3 < dd2; wd3++)
  170.            { wd4 = dd1[wd3];
  171.              if (wd2 != wd4)
  172.                { ft[wd2][wd4] = -100;
  173.                  printf("\n%s cannot be %s.",subjs[wd2],subjs[wd4]); }}}
  174. }
  175.  
  176. manugroup()
  177.    { int wk1, wk2, wk3, wk4, wk5, wk6, wk7, wk8, wk9, grpmems[MAX];
  178.       FILE *outfile;  char grpname[32], grpitem[77], answer[2];
  179.  
  180.      strcpy(grpitem,indff); /* make sure while loop does not abend */
  181.      wk9 = 0;
  182.      while (grpitem[0] != 'E' && wk9 < MAX)
  183.        { printf("\n\n\nEnter the contents for group member # %d.",wk9);
  184.          printf("\nIt will NOT be edited for proper syntax.");
  185.          printf("\nEnter 'E' to end making entries.\nThe entry: ");
  186.          gets(grpitem);
  187.          wk8 = findmem(grpitem);
  188.          if (wk8 < MAX)
  189.            { grpmems[wk9] = wk8; wk9++;
  190.              printf("\n  Subject found."); }}
  191.  
  192.      if (wk9 > 0)
  193.        { markgrup(grpmems,wk9);
  194.          printf("\nSave group (Y/N)? ");
  195.          gets(answer);
  196.          if (answer[0] == 'Y')
  197.           { printf("\nEnter the name under which the group will be stored.");
  198.             printf("\nFile name:  ");
  199.             gets(grpname);
  200.             outfile = fopen(grpname,"w");
  201.             if (outfile == NULL)
  202.                failfile();
  203.             else
  204.               { filestat = 0;
  205.                 printf("\n\nSaving group.");
  206.                 filestat = fprintf(outfile," %d ",wk9);
  207.                 for (wk1 = 0; wk1 < wk9; wk1++)
  208.                   { wk4 = grpmems[wk1];
  209.                     wk7 = strlen(subjs[wk4]);
  210.                     wk3 = fprintf(outfile," %d",wk7);
  211.                     if  (wk3 == -1)
  212.                        filestat = 1;
  213.                     wk3 = fputs(subjs[wk4],outfile);
  214.                     if (wk3 == -1)
  215.                        filestat = 1; }
  216.                     wk3 = fflush(outfile);
  217.                     if (wk3 != 0)
  218.                        filestat = wk3;
  219.                     wk3 = fclose(outfile);
  220.                     if (filestat != 0 || wk3 != 0)
  221.                       failfile(); }}}
  222. }
  223.